require 'View/UIBase/UIBase'

UICitySayHello = UIBase.New(PanelResNames.UICitySayHello)

function UICitySayHello.Init()
    UIBase.Init(UICitySayHello);
end

-- 创建回调
function UICitySayHello:OnCreate()
    self.iconEmoji = self:GetChild("iconEmoji");
    self.helloText = self:GetChild("hello");
    self.name = self:GetChild("name");
    self:RegisterOnClick(self.name,self.OnGo);
    self:RegisterOnClick(self:GetChild("btnNext"),self.Refresh);
    self:RegisterOnClick(self:GetChild("btnBg"),self.Refresh);
end

-- 显示
function UICitySayHello:OnEnable()
    self:Refresh();
end

function UICitySayHello:Refresh()
    self.helloData = logicMgr.ChatManager.getOneHello();
    if self.helloData == nil then
        self:OnClose();
        FireEvent(Config.EventType.Fresh_GetOneHello);
    else
        logicMgr.ChatManager.removeOneHello();
        self:UpdateData();
        FireEvent(Config.EventType.Fresh_GetOneHello);
    end
end

function UICitySayHello:UpdateData()
    self.iconEmoji.url = "ui://Emoji/e"..self.helloData.emojiId;
    self.helloText.text = getLanguage("SayHelloMessage"..self.helloData.emojiId);
    self.name.text = string.format(getLanguage("Sys_SayHelloInfo"), self.helloData.playerName);
    -- 打招呼音效
    AudioManager.Play(2016)
end

-- 详情
function UICitySayHello:OnGo()
    roleInfoHandler.sendreqOtherRoleInfo(self.helloData.playerId);
end

-- 关闭
function UICitySayHello:OnClose()
    self:OnBack();
end

-- 隐藏
function UICitySayHello:OnDisable()
end

-- 卸载
function UICitySayHello:OnDestroy()
end

return UICitySayHello